Ext.define('CA.base.LocaleCombo',{
    extend: 'Ext.form.field.ComboBox',
    xtype: 'CA.base.LocaleCombo',

    queryMode: 'local',
    valueField: 'key',
    displayField: 'value',
    editable: false,

    initComponent: function(){
        Ext.apply(this, {
            store: this.buildStore()
        });

        this.callParent();
    },

    setValue: function(val, doSelect){
        if(Ext.isString(val)){
            var index = this.store.find('key', val),
                rec = this.store.getAt(index);

            if(rec){
                val = [rec];
            }
        }

        this.callParent(arguments);
    },

    buildStore: function(){
        var data = [];

        Ext.Object.each(this.locale, function(k, v){
            data.push({ key: k, value: v });
        });

        return {
            xtype: 'Ext.data.Store',
            fields: ['key','value'],
            idProperty: 'key',
            data: data
        };
    }
});
